﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using RootobjectName;

namespace DictionaryName
{
    public class Dictionary
    {
        Dictionary<String, String> icons;
        //天气图标 
        public void getIcons()
        {
            icons = new Dictionary<String, String>();
            icons.Add("晴", "a_0.gif");
            icons.Add("多云", "a_1.gif");
            icons.Add("阴", "a_2.gif");
            icons.Add("阵雨", "a_3.gif");
            icons.Add("雷阵雨", "a_4.gif");
            icons.Add("雷阵雨并伴有冰雹", "a_5.gif"); 
           
            icons.Add("强沙尘暴", "a_31.gif");
            icons.Add("没有数据", "a_nothing.gif");
        }
        public void getWeatherItem(Rootobject w)
        {
            if (w.now != null)
            {
                KeyValuePair<String, String> obj = icons.FirstOrDefault(x =>x.Key.IndexOf(w.now.text) >= 0 || w.now.text.IndexOf(x.Key) >= 0);
                if (!obj.Equals(null))
                {
                    w.now.icon = "icon\\" + obj.Value;
                }
                else
                {
                    w.now.icon = null;
                }
                w.now.text = "天气状况：" + w.now.text;
                w.now.temp = "现在温度：" + w.now.temp;
            }
            if (w.daily != null)
            {
                foreach (Daily df in w.daily)
                {
                    KeyValuePair<String, String> objdf = icons.FirstOrDefault(x =>x.Key.IndexOf(df.textDay) >= 0 || df.textDay.IndexOf(x.Key) >= 0);
                    if (!objdf.Equals(null))
                    {
                        df.iconDay = "icon\\" + objdf.Value;
                    }
                    else
                    {
                        df.iconDay = null;
                    }
                    df.textDay = "天气状况：" + df.textDay;
                    df.tmp1 = "温度：" + df.tempMin + "-" + df.tempMax;
                }
            }
        }
    }
}
